<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
	<div class="wrapper wrapper-content ">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<input id="pageType" th:value="${pageType}"  type="hidden">
						<form class="form-horizontal m-t" id="signupForm">
						<input id="id" name="id" th:value="${config.id}"  type="hidden">
							<div class="form-group">	
								<label class="col-sm-3 control-label"><em class="text-danger">*&nbsp;</em>键：</label>
								<div class="col-sm-8">
									<input id="k" name="k" th:value="${config.k}" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label"><em class="text-danger">*&nbsp;</em>值：</label>
								<div class="col-sm-8">
									<input id="v" name="v" th:value="${config.v}" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">备注：</label>
								<div class="col-sm-8">
									<textarea id="remark" name="remark" class="form-control" rows="3" th:text="${config.remark}" ></textarea>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-8 col-sm-offset-5">
									<button type="submit" class="btn btn-primary">提交</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
	</div>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript" >
        $().ready(function() {
            var pageType = $('#pageType').val();
            if('save'==pageType){//新增页面
                validateRule();
            }else if('update'==pageType){//修改页面
                validateRule();
            }else{
                $('button[type="submit"]').addClass("hidden");
                parent.layer.msg("页面参数错误");
            }

        });

        $.validator.setDefaults({
            submitHandler : function() {
                save();
            }
        });

        function save() {
            $.ajax({
                cache : true,
                type : "POST",
                url : "/common/config/"+$('#pageType').val(),
                data : $('#signupForm').serialize(),// 你的formid
                async : false,
                error : function(request) {
                    parent.layer.alert("Connection error");
                },
                success : function(data) {
                    if (data.code == 0) {
                        parent.layer.msg("操作成功");
                        $(window.parent.document).find('.J_iframe').each(function () {
                            if ($(this).data('id') == "/common/config") {//common/sysDict为打开的frame id
                                this.contentWindow.reLoad();
                                return false;
                            }
                        });
                        var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                        parent.layer.close(index);
                    } else {
                        parent.layer.alert(data.msg)
                    }

                }
            });

        }
        function validateRule() {
            var icon = "<i class='fa fa-times-circle'></i> ";
            $("#signupForm").validate({
                rules : {
                    k:{
                        required : true
                    },
                    v :{
                        required : true
                    }
                },
                messages : {
                    k : {
                        required : icon + "请输入键k"
                    },v : {
                        required : icon + "请输入值v"
                    }
                }
            })
        }
	</script>
</body>
</html>
